<template>
	<view class="pics">
		<scroll-view class="left" scroll-y="true">
			<view :class="{active : active === index}" v-for="(item,index) in cates" :key="item.miniWallkey"
				@click="avtiveClick(index,item.maitKey)">{{item.title}}</view>
		</scroll-view>
		<scroll-view class="right" scroll-y="true">
			<view class="item" v-for="(i,index) in detail" :key="index">
				<image @click="preViewImg(i.image)" :src="i.image"></image>
				<text>{{i.title}}</text>
			</view>
			<text v-if="detail.length === 0" style="font-size: 30rpx;margin: 160rpx 160rpx">--暂无数据--</text>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cates: [],
				active: 0,
				detail: []
			}
		},
		onLoad() {
			this.getPicsCate()
		},
		methods: {
			async getPicsCate() {
				const res = await this.$myRequest({
					url: '/category'
				})
				if (res) {
					this.cates = res.data.data.category.list
					this.avtiveClick(0,this.cates[0].maitKey)
				}
			},
			async avtiveClick(index, id) {
				this.active = index
				const res = await this.$myRequest({
					url: '/subcategory?maitKey=' + id
				})
				if(res){
					this.detail = res.data.data.list
				}
			},
			preViewImg(current){
				const urls = this.detail.map(item => {
					return item.image
				})
				uni.previewImage({
					current,
					urls,
					loop:true,
				})
				
			}

		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
	}

	.pics {
		height: 100%;
		display: flex;
		.left {
			width: 200rpx;
			height: 100%;
			border-right: 1px solid #eee;

			view {
				height: 140rpx;
				line-height: 140rpx;
				color: #333;
				text-align: center;
				font-size: 35rpx;
				border-top: 1px solid #eee;
			}

			.active {
				background: $shop;
				color: #fff;
			}
		}
		.right{
			height: 100%;
			width: 520rpx;
			margin: 5px auto;
			.item{
				image{
					width: 520rpx;
					height: 520rpx;
					border-radius: 6px;
				}
				text{
					font-size: 32rpx;
					line-height: 60rpx;
				}
			}
		}
	}
</style>
